from table_ceil import table
import sys
import os
import cv2


def main(img_dir):
    files = os.listdir(img_dir)
    for f_path in files:
        try:
            if 'jpg' not in os.path.splitext(f_path)[1]:
                continue
            image = cv2.imread(os.path.join(img_dir, f_path))
            tableDetect = table(
                image, 
                tableSize=[416,416],
                tableLineSize=[1024,1024],
                isTableDetect=False,
                isToExcel=False
            )
            print(f'{f_path}处理完成')
            print(tableDetect.res)
            break
        except Exception as e:
            print(f'处理{f_path}时发生异常：{e}')


if __name__ == '__main__':
    arg = sys.argv[1]
    if arg:
        if not os.path.exists(arg) or not os.path.isdir(arg):
            print('输入的路径不存在或不是一个目录')
            sys.exit()
        main(arg)